package com.wang.head.servlet;

import com.wang.common.servlet.BaseServlet;
import com.wang.common.util.PageInfoUtil;
import com.wang.users.service.IUsersDbService;
import com.wang.users.service.impl.UsersDbServiceImpl;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


/**
 * 第二个Servlet 只存储和管理员息息相关的信息 登陆后的操作
 *
 * @author wangshMac
 */
@WebServlet(urlPatterns = "/MainHeadServlet")
public class MainHeadServlet extends BaseServlet {
    private IUsersDbService usersDbService;

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        UsersDbServiceImpl usersDbServiceImpl = new UsersDbServiceImpl();
        this.usersDbService = usersDbServiceImpl;

    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        /* 接收参数 */
        String method = request.getParameter("method");
        if ("main".equalsIgnoreCase(method)) {
            /* 登陆后首页 */
            main(request, response);
        } else if ("header".equalsIgnoreCase(method)) {
            /* 网页头部 */
            header(request, response);
        }
    }

    /**
     * 首页
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws ServletException
     */
    private void main(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /* 准备路径 */
        this.path = "/WEB-INF/jsp/head/main.jsp";
        /* 页面跳转 */
        request.getRequestDispatcher(path).forward(request, response);
    }

    /**
     * header
     *
     * @param request
     * @param response
     * @throws IOException
     * @throws ServletException
     */
    private void header(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /* 准备路径 */
        this.path = "/WEB-INF/jsp/head/header.jsp";
        /* 页面跳转 */
        request.getRequestDispatcher(path).include(request, response);
    }
}